<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Controller;

use App\Log;
use function Hyperf\Coroutine\co;
use function Swoole\Coroutine\go;

class IndexController extends AbstractController
{
    public function index()
    {
        $user = $this->request->input('user', 'Hyperf');
        $method = $this->request->getMethod();

        $mobile=$this->request->input('mobile', '');

        Log::get('default','default')->info(__CLASS__.__METHOD__);
        Log::get('mypay','mypay')->info(__CLASS__.__METHOD__);
        //两种启动协程的方式
        co(function () use ($mobile){
            //co 启动一个协程
            Log::get('mypay','mypay')->info('co1 into:'.$mobile.'xxx'.time());
            sleep(3);
            Log::get('mypay','mypay')->info('co1 out:'.$mobile.'xxx'.time());
        });
        go(function ()use($mobile){
            //go 启动一个协程
            Log::get('mypay','mypay')->info('go1 into:'.$mobile.'xxx'.time());
            sleep(3);
            Log::get('mypay','mypay')->info('go2 out:'.$mobile.'xxx'.time());
        });
        Log::get('mypay','mypay')->info('return:'.time());
        return [
            'method' => $method,
            'message' => "Hello {$user}.",
        ];
    }
}
